﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZOVNP.Model.Abstracts;

namespace ZOVNP.Engine
{
    [DomainObject(typeof(IProduct))]
    public partial class Product : IProduct
    {
        private IDomainReference<IProductType> _productTypeLocker;
        private IDomainCollection<IPriceItem> _priceItemsLocker;


        public Product()
        {
            _productTypeLocker = new SmartReference<Product, ProductType, IProductType>(this, ProductTypeReference, it => it.ProductTypeID);
            _priceItemsLocker = new SmartCollection<PriceItem, IPriceItem>(this, PriceItems);
        }

        IDomainReference<IProductType> IProduct.ProductTypeReference
        {
            get { return _productTypeLocker; }
        }

        IProductType IProduct.ProductType
        {
            get
            {
                return _productTypeLocker.Value;
            }
            set
            {
                _productTypeLocker.Value = value;
            }
        }

        IDomainCollection<IPriceItem> IProduct.PriceItems
        {
            get { return _priceItemsLocker; }
        }

        public string GetKeyName()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Name);
            if (!string.IsNullOrWhiteSpace(Producer))
                sb.AppendFormat(" {0}", Producer);
            if (!string.IsNullOrWhiteSpace(Property1))
                sb.AppendFormat(" {0}", Property1);
            if (!string.IsNullOrWhiteSpace(Property2))
                sb.AppendFormat(" {0}", Property2);
            if (!string.IsNullOrWhiteSpace(Property3))
                sb.AppendFormat(" {0}", Property3);

            return sb.ToString();
        }

        public override string ToString()
        {
            return Name;
        }
    }
}
